package com.xl.rentkeeper.act.jilu;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import com.xl.rentkeeper.App;
import com.xl.rentkeeper.R;
import com.xl.rentkeeper.act.BaseAct;
import com.xl.rentkeeper.entity.Order;
import com.xl.rentkeeper.util.Util;
import com.xl.rentkeeper.view.TitleBar;

/**
 * Created by Administrator on 2015/8/17.
 */
public class SignedDetailAct extends BaseAct implements View.OnClickListener {
    private Order mOrder;
    private String mTitle;

    private TextView mTVName;
    private TextView mTVPhone;
    private TextView mTVIDNumber;
    private TextView mTVJob;
    private TextView mTVTime;
    private TextView mTVRoomName;
    private TextView mTVRoomPrice;//房间价格
    private TextView mTVSignTime;
    private TextView mTVBeginTime;
    private TextView mTVEndTime;

    private TextView mTVCall;
    private TitleBar tb;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_signed_detail1);
        tb = (TitleBar) findViewById(R.id.tb);
        setTranslucentStatus();
        mOrder = (Order) getIntent().getSerializableExtra("msg");
        mTitle = getIntent().getStringExtra("title");
        tb.setTitleName(mTitle);
        initTitleBar(tb);
        initView();
        initData();
    }

    private void initView() {
        mTVName = (TextView) findViewById(R.id.tv_name);
        mTVPhone = (TextView) findViewById(R.id.tv_phone);
        mTVIDNumber = (TextView) findViewById(R.id.tv_id_number);
        mTVJob = (TextView) findViewById(R.id.tv_job);
        mTVTime = (TextView) findViewById(R.id.tv_orderTime);

        mTVRoomName = (TextView) findViewById(R.id.tv_roomName);
        mTVRoomPrice = (TextView) findViewById(R.id.tv_roomPrice);
        mTVSignTime = (TextView) findViewById(R.id.tv_signTime);
        mTVBeginTime = (TextView) findViewById(R.id.tv_beginTime);
        mTVEndTime = (TextView) findViewById(R.id.tv_endTime);

        mTVCall = (TextView) findViewById(R.id.tv_phone);
        mTVCall.setOnClickListener(this);

    }

    private void initData() {
      /*  Intent intent = this.getIntent();
        mOrder = (Order) intent.getSerializableExtra("msg");*/

        mTVName.setText(mOrder.viewOrder.name);
        mTVTime.setText(Util.replaceTimeNull(mOrder.viewOrder.viewTime));

        if (TextUtils.isEmpty(mOrder.viewOrder.phone)) {
            mTVPhone.setText(Util.replaceNull(null,mOrder.viewOrder.phone));
            mTVCall.setVisibility(View.INVISIBLE);

        } else {
            mTVPhone.setText(Util.replaceNull(null,mOrder.viewOrder.phone));
        }
        if(mOrder.viewOrder.signInfo!=null){
            mTVIDNumber.setText(Util.replaceNull("",mOrder.viewOrder.signInfo.IdNumber));
            mTVBeginTime.setText(Util.replaceTimeYMDNull(mOrder.viewOrder.signInfo.contractStartTime));
            mTVEndTime.setText(Util.replaceTimeYMDNull(mOrder.viewOrder.signInfo.contractEndTime));
        }else {
            mTVIDNumber.setText(Util.replaceNull(null, "未填写"));
            mTVBeginTime.setText(Util.replaceNull(null, "未填写"));
            mTVEndTime.setText(Util.replaceNull(null,"未填写"));
        }

        mTVJob.setText(Util.replaceNull("", mOrder.viewOrder.job));

        Util.setSignPrice(mTVRoomPrice,mOrder.viewOrder.signInfo,"signDetail");
        if (mOrder.viewOrder.signRoom==null ) {
            mTVRoomName.setText("未填写");
        }else{
            mTVRoomName.setText(Util.replaceNull("",mOrder.viewOrder.signRoom.name));
        }
        mTVSignTime.setText(Util.replaceTimeNull(mOrder.viewOrder.signTime));

    }


    @Override
    public void onClick(View v) {
        if (v == mTVCall) {
            if (TextUtils.isEmpty(mOrder.viewOrder.phone)) {
                App.showToast("没有客户电话号码");
            } else {
                Uri uri = Uri.parse("tel:" + mOrder.viewOrder.phone);
                Intent intent = new Intent(Intent.ACTION_DIAL, uri);
                startActivity(intent);
            }
        }
    }
}
